package com.yonyou.marketing.app.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.AppResponse;
import org.marketing.common.constants.ResultMsgConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.marketing.app.api.constant.AppConstant;
import com.yonyou.marketing.app.api.model.TmRegulationsThrid;
import com.yonyou.marketing.app.api.service.AppViolationInquiryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = AppConstant.BASE_PATH + "/" + AppConstant.VERSION)
@Api("违章查询")
public class AppViolationInquiryController {
	private Logger          logger = Logger.getLogger(AppLoginController.class);
	
	@Autowired
	private AppViolationInquiryService appViolationInquiryService;
	
	/**
	 * 查询指定省 发动机号和车架号
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/checkCarReg", method = RequestMethod.POST)
	@ApiOperation(value = "查询指定省 发动机号和车架号", notes = "查询指定省 发动机号和车架号")
	public AppResponse<Map<String, Object>> checkCarReg(@RequestParam(required=true,defaultValue="") String cityCode) {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, appViolationInquiryService.checkCarReg(cityCode) ,"");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 返回违章车辆信息
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/queryCarReg", method = RequestMethod.POST)
	@ApiOperation(value = "返回违章车辆信息", notes = "返回违章车辆信息")
	public AppResponse<Map<String, Object>> updateCarReg(@RequestParam(required=true,defaultValue="贵BAX383") String registNo
			,@RequestParam(required=false,defaultValue="") String vin
			,@RequestParam(required=false,defaultValue="") String engine
			,@RequestParam(required = true, defaultValue = "") String city
			,@RequestParam(value = "userId",required = false,defaultValue = "") String userId) {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, 
					appViolationInquiryService.updateCarReg(registNo, vin, engine, userId,city),"");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 进入违章页面前调用：校验车主
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/checkCar", method = RequestMethod.POST)
	@ApiOperation(value = "校验车主", notes = "校验车主")
	public AppResponse<Map<String, Object>> checkCar(
			@RequestParam(value = "userId",required = false,defaultValue = "") String userId) {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, 
					appViolationInquiryService.checkCar(userId),"");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 违章查询历史
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/findHistory", method = RequestMethod.POST)
	@ApiOperation(value = "违章查询历史", notes = "违章查询历史")
	public AppResponse<List<TmRegulationsThrid>> findHistory(
			@RequestParam(value = "userId",required = false,defaultValue = "") String userId) {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, 
					appViolationInquiryService.findHistory(userId),"");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 清空历史
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/deleteHistory", method = RequestMethod.POST)
	@ApiOperation(value = "清空历史", notes = "清空历史")
	public AppResponse<Integer> deleteHistory(@RequestParam(value = "userId",required = false,defaultValue = "") String userId) {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, 
					appViolationInquiryService.deleteHistory(userId),"");
		} catch (Exception e) {
			logger.error("状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
	
	/**
	 * 违章查询简称
	 * @author Administrator
	 * @date 2017年12月4日
	 * @return
	 */
	@RequestMapping(value = "/findProvince", method = RequestMethod.POST)
	@ApiOperation(value = "违章查询简称", notes = "违章查询简称")
	public AppResponse<List<Map<String,Object>>> findProvince() {
		try {
			return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, 
					appViolationInquiryService.findProvince(),"");
		} catch (Exception e) {
			logger.error("状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
		}
	}
}
